package bootstrap.liftweb

import net.liftweb.util._
import net.liftweb.common._
import net.liftweb.http._
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import Helpers._
import net.liftweb.mapper.{DB, ConnectionManager, Schemifier, DefaultConnectionIdentifier, ConnectionIdentifier}
import java.sql.{Connection, DriverManager}
//import com.mycompany.mavenproject1.model._
 
/**
 * A class that's instantiated early and run.  It allows the application
 * to modify lift's environment
 */
class Boot {
  def boot {

//    LogBoot.defaultProps =
//      """<?xml version="1.0" encoding="UTF-8" ?>
//    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
//    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
//      <appender name="appender" class="org.apache.log4j.ConsoleAppender">
//        <layout class="org.apache.log4j.SimpleLayout"/>
//      </appender>
//      <root>
//        <priority value="TRACE"/>
//        <appender-ref ref="appender"/>
//      </root>
//    </log4j:configuration>"""


    //if (!DB.jndiJdbcConnAvailable_?) DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
    // where to search snippet
    LiftRules.addToPackages("hu.kovacsp.scala.discovery.web")
    //Schemifier.schemify(true, Log.infoF _, User)

    //LiftRules.addTemplateBefore(User.templates)

    // Build SiteMap
    //val entries = Menu(Loc("Home", new net.liftweb.sitemap.Loc.Link("/"), "Home")) :: Nil
    //val entries = Menu(Loc("Extlink", ExtLink("http://www.liftweb.net/"), "LiftWeb")) :: Nil
    val entries =
      Menu(Loc("Home", List("index"), "Home")) ::
      Menu(Loc("Test", List("codesearch"), "Test Page 5")) ::
      Menu(Loc("Extlink", ExtLink("http://www.liftweb.net/"), "LiftWeb")) ::
      Nil
    LiftRules.setSiteMap(SiteMap(entries: _*))
    //S.addAround(User.requestLoans)
  }

  // set DocType to HTML5
//  LiftRules.docType.default.set((r: Req) => r match {
//      case _ if S.skipDocType => Empty
//      case _ if S.getDocType._1 => S.getDocType._2
//      case _ => Full(DocType.html5)
//    })
}


//object DBVendor extends ConnectionManager {
//  def newConnection(name: ConnectionIdentifier): Can[Connection] = {
//    try {
//      Class.forName("org.apache.derby.jdbc.EmbeddedDriver")
//      val dm = DriverManager.getConnection("jdbc:derby:lift_example;create=true")
//      Full(dm)
//    } catch {
//      case e : Exception => e.printStackTrace; Empty
//    }
//  }
//  def releaseConnection(conn: Connection) {conn.close}
//}

